package com.elecbook.content.api.controller;

import com.elecbook.base.dto.PageDTO;
import com.elecbook.base.result.Result;
import com.elecbook.content.model.dto.ContributeJudgePageDTO;
import com.elecbook.content.model.dto.ContributeJudgeSubmitDTO;
import com.elecbook.content.model.dto.ContributejudgePQuery;
import com.elecbook.content.model.po.Contributejudge;
import com.elecbook.content.service.ContributejudgeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("ContributeJudgeController")
@RequestMapping("/contributeJudge")
@Slf4j
public class ContributeJudgeController {

    @Autowired
    private ContributejudgeService contributejudgeService;
    @PostMapping("/submit")
    public Result<Contributejudge> sumbitJudge(@RequestBody ContributeJudgeSubmitDTO dto)
    {
        Contributejudge contributejudge = contributejudgeService.submitJudge(dto);
        return Result.success(contributejudge);
    }

    @PostMapping("/page")
    public  Result<PageDTO<Contributejudge>> page(@RequestBody ContributeJudgePageDTO pageDTO)
    {
        PageDTO<Contributejudge> pageResult = contributejudgeService.queryContributeJudgePage(pageDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/{contributeJudgeId}")
    public  Result<Contributejudge> page(@PathVariable Integer contributeJudgeId)
    {
        Contributejudge contributejudge = contributejudgeService.getContributeJudgeById(contributeJudgeId);
        return Result.success(contributejudge);
    }



        /*
    管理员生成方法
    */

    @PostMapping("/op/save")
    Result<Contributejudge> save(@RequestBody Contributejudge contributejudge) {
        Contributejudge res = contributejudgeService.saveContributejudge(contributejudge);
        return Result.success(res);
    }

    @DeleteMapping("/op/{id}")
    Result<String> delete(@PathVariable Long id) {
        contributejudgeService.removeById(id);
        return Result.success();
    }

    @GetMapping("/op/{id}")
    Result<Contributejudge> get(@PathVariable Long id) {
        Contributejudge res =  contributejudgeService.getById(id);
        return Result.success(res);
    }

    @PutMapping("/op/update")
    Result<Contributejudge> update(@RequestBody Contributejudge contributejudge) {
        Contributejudge res =  contributejudgeService.updateContributejudgeById(contributejudge);
        return Result.success(res);
    }

    @PostMapping("/op/page")
    Result<PageDTO<Contributejudge>> page(@RequestBody ContributejudgePQuery contributejudgeQuery) {
        PageDTO<Contributejudge> pageResult = contributejudgeService.pageQuery(contributejudgeQuery);
        return Result.success(pageResult);
    }
}
